const CONFIG = require('../../config.js')
// 文案匹配
let TEXTData = {};
Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		navBgColor: '-webkit-gradient(linear, 0% 0%, 0% 100%,from(#1b64e5), to(#488dea))',
		reportData: {},
		reportId: '',
		loginInfo: '',
		educationName: '',
		occupationName: '',
		financingPreferenceName: '',
		canvasHidden: false,
		postUrl: '',
		type1: false,
		type2: false,
		type3: false,
		textJsonData: []
	},

	// 匹配学历
	getEdu(type){
		switch(type){
			case 1:
				return '高中及以下';
				break;
			case 2:
				return '大专';
				break;
			case 3:
				return '本科';
				break;
			case 4:
				return '研究生';
				break;
			case 5:
				return '博士';
				break;
			default:
				return '';
		}
	},
	// 匹配职业
	getOccu(type){
		switch(type){
			case 1:
				return '工薪族';
				break;
			case 2:
				return '企业主';
				break;
			case 3:
				return '自由职业';
				break;
			default:
				return '';
		}
	},
	// 匹配融资偏好
	getfinancingPreference(type){
		switch(type){
			case 1:
				return textJsonData.dengebenjin;
				break;
			case 2:
				return textJsonData.dengebenxi;
				break;
			case 3:
				return textJsonData.xianxihouben;
				break;
			case 4:
					return textJsonData.houxihouben;
					break;
			default:
				return '';
		}
	},

	// 获取报告数据
	getReportData: function (reportId){
		this.setData({
			reportData: {
				userName: '产品1： 广发'
			}
		})
		wx.request({
			url: CONFIG.host + "/system/orderInfoController/getOrderInfoForAPP",
			data: {
				id : reportId
			},
			method: "GET",
			header: {
				'content-type': 'application/json',
				'Authorization': this.data.loginInfo.token
			},
			success: res => {
				if(res.data.code === 'success'){
					let datas = res.data.data;
					let type1 = datas.matchInfo.payType.indexOf('1') > -1;
					let type2 = datas.matchInfo.payType.indexOf('2') > -1;
					let type3 = datas.matchInfo.payType.indexOf('3') > -1;
            		let type4 = datas.matchInfo.payType.indexOf('4') > -1;
					this.setData({
						reportData: datas,
						type1: type1,
						type2: type2,
						type3: type3,
						type4: type4,
						educationName: this.getEdu(datas.matchInfo.education),
						occupationName: this.getOccu(datas.matchInfo.occupation),
						financingPreferenceName: this.getfinancingPreference(datas.matchInfo.financingPreference),
					})
				}
			},fail: function (error) {
				console.log(error);
			}
		})
	},

	saveImageToAlbum: function() {
		var that = this;
		//将图片保存到相册       
		wx.saveImageToPhotosAlbum({
		  filePath: that.data.postUrl,
		  success(res) {
			wx.showModal({
			  title: '保存成功',
			  content: '图片成功保存到相册了，快去分享朋友圈吧',
			  showCancel: false,
			  confirmText: '好的',
			  confirmColor: '#818FFB',
			  success: function(res) {
				if (res.confirm) {
				//   that.setData({
				// 	showPosterImage: true
				//   })
				}
			  }
			})
		  }
		})
	  },
	
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
			let showNum = wx.getStorageSync('showUser') === '0' ? '0' : '1';
			TEXTData = require('../../utils/text'+ showNum +'.js');
			let loginInfo = wx.getStorageSync('loginInfo') || '';
			if(loginInfo){
				this.setData({
					loginInfo : JSON.parse(loginInfo),
					textJsonData: TEXTData.textJson
				})
			}
			this.setData({
				reportId: options.reportId || '77abaf14-3d48-49a5-b95e-e6a000121a06',
			})
    },
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
		this.getReportData(this.data.reportId);
	},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})